package ModelLayer;
import java.util.ArrayList;

public class CustomerList
{
    
    private ArrayList<Customer> customers;
    private static CustomerList instance;

    
    public CustomerList()
    {
       customers = new ArrayList<Customer>();
    }

    public static CustomerList getInstance()
    {
        if (instance == null)
        {
            instance = new CustomerList();
        }
        return instance;
    }
    
    public void addCustomer(Customer newCustomer)
    {
        customers.add(newCustomer);
    }
    
     public void deleteCustomer(int customerId)
    {
        Customer customer = findCustomer(customerId);
        customers.remove(customer);
    }
  
    
    public  Customer findCustomer( int customerId)
    {
    boolean customerFound = false;
    int index = 0;
    
        while(index < customers.size() && !customerFound)
        {
            Customer s = customers.get(index);
            if(s.getCustomerId() == customerId)
            {
                customerFound = true;
            }
            else
            {
                index++;
            }
    }
    
    if(customerFound)
    {
        return customers.get(index);
    }
    else
    {
        
        return null;
       
    }

   }
   }